import { BasicColumn, FormSchema } from '/@/components/Table';
import { DictCodeEnum, getDictItems, getDictItemMap } from '/@/utils/dict';

// 登录状态字典数据
const loginStatusDict = getDictItems(DictCodeEnum.LOGIN_STATUS);
const loginStatusDictMap = getDictItemMap(DictCodeEnum.LOGIN_STATUS);

export const columns: BasicColumn[] = [
  {
    title: '用户账号',
    dataIndex: 'username',
  },
  {
    title: '登录IP地址',
    dataIndex: 'loginIp',
  },
  {
    title: '登录地点',
    dataIndex: 'loginLocation',
  },
  {
    title: '操作系统',
    dataIndex: 'os',
  },
  {
    title: '浏览器',
    dataIndex: 'browser',
  },
  {
    title: '提示消息',
    dataIndex: 'msg',
  },
  {
    title: '登录状态',
    dataIndex: 'loginStatus',
    dictFormat: loginStatusDictMap,
  },
  {
    title: '登录时间',
    dataIndex: 'createTime',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'username',
    label: '用户账号',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'loginStatus',
    label: '登录状态',
    component: 'Select',
    componentProps: {
      options: loginStatusDict,
    },
    colProps: { span: 6 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'ID',
    component: 'Input',
    show: false,
  },
  {
    field: 'username',
    label: '用户账号',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },
  {
    field: 'loginIp',
    label: '登录IP地址',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },
  {
    field: 'loginLocation',
    label: '登录地点',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },
  {
    field: 'ua',
    label: 'UA',
    component: 'InputTextArea',
    componentProps: {
      readonly: true,
    },
    colProps: { lg: 24, md: 24 },
  },
  {
    field: 'browser',
    label: '浏览器类型',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },
  {
    field: 'os',
    label: '操作系统',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },
  {
    field: 'msg',
    label: '提示消息',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },
  {
    field: 'loginStatus',
    label: '登录状态',
    component: 'Select',
    componentProps: {
      options: loginStatusDict,
      disabled: true,
    },
  },
];
